
<?php
include('modelo.php');

session_start();
if (!isset($_SESSION['username']))
    header('Location: login.php');
$userId = $_SESSION['username'];

if (!$_GET['id'])
    header('Location: index.php');
$id = $_GET['id'];
if (!validExercice($id))
    header('Location: index.php');

$ej_name = executeScalar("select Nombre from Ejercicios where idEjercicio=$id");
echo "<h2>Problemas</h2>\n";
$sql = "select idProblema,nombre from EjercicioProblema inner join Problemas on idProblema=problemId where idEjercicio=$id";
$ans = executeQuery($sql);
$n = count($ans);
$ok = "<img src='resources/ok.png' width='20px' />";
$solved = getSolved($userId);
echo "<ul>";
if ($n > 0) {
    for ($i = 1; $i <= $n; $i++) {
        $row = $ans[$i-1];
        $idProb = $row['idProblema'];
        $problem = $row['nombre'];
        $link = "<a href='javascript:viewProblem($id,\"$idProb\")'>$problem</a>";
        if (in_array($idProb,$solved))
            echo "<li>$i. $link &nbsp; $ok</li>\n";
        else
            echo "<li>$i. $link</li>\n";
    }    
}
echo "</ul>";
?>

